
package model;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Arrays;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
//users has changed
public class Users {
    static String DATABASE_URL = "jdbc:mysql://localhost/education";
    static String JDBC_DRIVER = "com.mysql.jdbc.Driver";
    static Connection conn;
    static Statement stat;
    static ResultSet res;
    static List<String> list;
    public static boolean exists(User user){
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("WebApplication1PU");
        EntityManager em = emf.createEntityManager();
        return false;
    }
    public static List<String[]> getUsers(){
        String[][] array = null;
        try {
            Class.forName(JDBC_DRIVER);
            conn = DriverManager.getConnection(DATABASE_URL, "root", "");
            stat = conn.createStatement();
            res = stat.executeQuery("SELECT id, username, password FROM user");
            int rowcount = 0;
            if (res.last()) {
                rowcount = res.getRow();
                System.out.println(rowcount);
                res.beforeFirst();
            }
            System.out.println("rowcount " + rowcount);
            array = new String[rowcount][3];
            int r = 0;
            while (res.next()) {
                array[r][0] = res.getString(2);
                array[r][1] = res.getString(3);
                array[r][2] = (res.getInt(1)+"");
                r++;
            }
            conn.close();
        } catch (Exception ex) {
        }
        return Arrays.asList(array);
    }
    
    public static void main(String [] args){
        List<String []> a = Users.getUsers();
        for(String s[]: a){
            System.out.println(s[0]+" "+s[1]);
        }
    }
}
